home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2113 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: iostream-stdio speed - again
  5. Date: 15 Jan 1996 23:09:33 GMT
  6. Organization: Kalevi, Inc
  7. Message-ID: <4demrd$mkr@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe9.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. Remember the recent thread with similar subject? Some of us,  
  15. including I, stated that the 4:1 ratio iostream vs. stdio 
  16. was excessive -- possibly due to the original poster using  
  17. an old compiler:  BC 2.0, I think. 
  18.  
  19. I take it all back!  I just had a need to process a 56mb text  
  20. file by reading it in a line at a time, making an insignificant  
  21. mod, and writing the line to another file.  I decided to try a 
  22. stdio version as well as an iostream one.  I used what I consider  
  23. to be equivalent code.  Compiler was MSVC++ 4.0 running in Windows  
  24. NT 3.51.  No time to test with other compilers right now. 
  25.  
  26. The results: 
  27.  
  28. LIBRARY       TIME 
  29. stdio         3:44 
  30. iostream     12:17  
  31.  
  32. Significant details: 
  33.  
  34. iostream: 
  35.   Loop 
  36.     is.getline(buf, xxx) 
  37.     minor mod 
  38.     os << buf << '\n'; 
  39.     // Note: dropped endl in case it caused extra 
  40.     // inefficiency due to flushing. 
  41.  
  42. stdio: 
  43.   Loop 
  44.     fgets(buf, xxx, infile); 
  45.     minor mod 
  46.     fputs(buf, outfile); 
  47.  
  48. Because this was a one-time mod, I didn't try to write more  
  49. efficient routine by using block reads  or the like.  I also realize 
  50. that some may disagree on the 'equivalency' of the two methods. 
  51.  
  52.  
  53. -- 
  54.  
  55. Pete 
  56.  
  57.  
  58.  
  59.  
  60.  
  61.